﻿using System;
using BITS.PreCompiler.CSharp.Syntax;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BITS.PreCompiler.CSharp.Tests.Syntax
{
    [TestClass]
    public class TestMethod
    {
        [TestMethod]
        public void Create_Method()
        {
            var @method = new Method(@return: "int", identifier: "MethodA");

            var expectet = Comparer.Create_Method();
            var actual   = @method.ToString();

            Assert.AreEqual(expectet, actual);
            Console.WriteLine(actual);
        }

        [TestMethod]
        public void Create_Abstract_Method()
        {
            var @method = new AbstractMethod(@return: "int", identifier: "MethodA");

            var expectet = Comparer.Create_Abstract_Method();
            var actual   = @method.ToString();

            Assert.AreEqual(expectet, actual);
            Console.WriteLine(actual);
        }

        [TestMethod]
        public void Create_Method_With_String_Body()
        {
            var @method = new Method(@return: "int", identifier: "MethodB")
            {
                @"int x = 0;",

                @"return x;",
            };

            var expectet = Comparer.Create_Method_With_String_Body();
            var actual   = @method.ToString();

            Assert.AreEqual(expectet, actual);
            Console.WriteLine(actual);
        }

        [TestMethod]
        public void Create_Method_With_Parameters()
        {
            var @method = new Method(identifier: "MethodB", parameters: "int z, string a")
            {
                @"int x = 0;",

                @"return x;",
            }
            .WithReturnType("int");

            var expectet = Comparer.Create_Method_With_Parameters();
            var actual   = @method.ToString();

            Assert.AreEqual(expectet, actual);
            Console.WriteLine(actual);
        }




        public static class Comparer
        {
            public static String Create_Method()
            {
                return
@"private int MethodA()
{
}";
            }

            public static String Create_Abstract_Method()
            {
                return
@"int MethodA();";
            }

            public static String Create_Method_With_String_Body()
            {
                return
@"private int MethodB()
{
    int x = 0;
    return x;
}";
            }

            public static String Create_Method_With_Parameters()
            {
                return
@"private int MethodB(int z, string a)
{
    int x = 0;
    return x;
}";
            }
        }
    }
}
